package com.zx.lean_ui.fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.zx.lean_ui.R;
import com.zx.lean_ui.interfaces.IFragmentCallback;
import com.zx.lean_ui.util.Config;

@SuppressLint("LongLogTag")
public class BlankFragment3 extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    View root;
    private Button blan3Btn;

    private  String TAG="BlankFragment3>>>>>>>>>>";    
    public BlankFragment3() {
        // Required empty public constructor
    }


    private IFragmentCallback fragmentCallback;

    public void setFragmentCallback(IFragmentCallback callback) {
        fragmentCallback = callback;
        Config.d("BlankFragment3","setFragmentCallback()");
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        Log.d(TAG, "onAttach: ");
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        Log.d(TAG, "onCreate: ");
        String message = bundle.getString("message");
        Config.d("BlankFragment3", "message" + message);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        //因为其可能会解析多次，所以将其定义成全局变量
        Log.d(TAG, "onCreateView: ");
        if (root==null) {
            root = inflater.inflate(R.layout.fragment_blank3, container, false);
        }
        initView(root);
        return root;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.d(TAG, "onActivityCreated: ");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.d(TAG, "onStart: ");
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.d(TAG, "onResume: ");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.d(TAG, "onPause: ");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d(TAG, "onStop: ");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.d(TAG, "onDestroyView: ");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy: ");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.d(TAG, "onDetach: ");
    }

    private void initView(View root) {
        blan3Btn = root.findViewById(R.id.blan3_btn);
        blan3Btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Config.d("BlankFragment3","onClick()");
                fragmentCallback.sendMsgToActivity("hello I am Fragment");
                String aNull = fragmentCallback.getMsgFromActivity("null");
                Config.d("BlankFragment3","onClick()aNull:=================="+aNull);
            }
        });
    }
}